package com.tamo.ppresta.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gyf.immersionbar.ImmersionBar;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.OnHttpListener;
import com.tamo.ppresta.BuildConfig;
import com.tamo.ppresta.R;
import com.tamo.ppresta.base.BaseActivity;
import com.tamo.ppresta.bean.LogOutBean;
import com.tamo.ppresta.constant.NET_CONSTANT;
import com.tamo.ppresta.constant.SPConstant;
import com.tamo.ppresta.event.LogOutEvent;
import com.tamo.ppresta.http.HttpData;
import com.tamo.ppresta.httpapi.LogOutApi;
import com.tamo.ppresta.util.ButtonUtils;
import com.tamo.ppresta.util.LogUtils;
import com.tamo.ppresta.util.MyUtils;
import com.tamo.ppresta.util.SPUtil;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author yeyang
 * @name ppresta
 * @class name：com.tamo.ppresta.activity
 * @class describe
 * @time 2022/12/22 19:46
 * @change
 * @chang time
 * @class describe
 */
public class AboutUsActivity extends BaseActivity {
    @BindView(R.id.iv_about_us_icon)
    ImageView mIvAboutUsIcon;
    @BindView(R.id.tv_app_version)
    TextView mTvAppVersion;
    @BindView(R.id.tv_about_us_tip)
    TextView mTvAboutUsTip;
    @BindView(R.id.tv_about_us_text)
    TextView mTvAboutUsText;
    @BindView(R.id.tv_login_out)
    TextView mTvLoginOut;
    @BindView(R.id.iv_title_back)
    ImageView mIvTitleBack;
    @BindView(R.id.rl_title_back)
    RelativeLayout mRlTitleBack;
    @BindView(R.id.tv_title_name)
    TextView mTvTitleName;

    @Override
    protected int setLayout() {
        return R.layout.activity_about_us;
    }

    @Override
    protected void setView() {
        mTvTitleName.setText(R.string.sobre_nosotros);
        mTvAppVersion.setText("Version: " + BuildConfig.VERSION_NAME);
        mRlTitleBack.setOnClickListener(this::onClick);
        mTvLoginOut.setOnClickListener(this::onClick);
    }

    @Override
    protected void setData() {

    }

    @Override
    public void onClick(View v) {
        ButtonUtils.isFastDoubleClick();
        switch (v.getId()) {
            case R.id.rl_title_back:
                finish();
                break;
            case R.id.tv_login_out:
                loginOut();
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        MyUtils.setStatusBarVisible(this);
        ImmersionBar.with(this)
                .statusBarColor(R.color.white)
                .transparentNavigationBar()  //透明导航栏，不写默认黑色(设置此方法，fullScreen()方法自动为true)
                .statusBarDarkFont(true)
                .init();
        ButterKnife.bind(this);
    }

    // TODO: 2022/12/22 退出登录跳转哪个页面
    private void loginOut() {
        EasyHttp.post(this)
                .api(new LogOutApi()
                        .setLanguageCode(NET_CONSTANT.LANGUAGE_CODE)
                        .setItemCode(NET_CONSTANT.ITEM_CODE)
                        .setSessionId(SPUtil.getString(getApplicationContext(), SPConstant.SP_NAME, SPConstant.SP_SESSIONID))
                )
                .request(new OnHttpListener<HttpData<LogOutBean>>() {
                    @Override
                    public void onSucceed(HttpData<LogOutBean> data) {
                        if (null != data && null != data.getData()) {
                            LogUtils.info(TAG, "data: " + data);
                        } else {
                            LogUtils.info(TAG, "data: 是null");
                        }
//                        SPUtil.remove(getApplicationContext(), SPConstant.SP_NAME, SPConstant.SP_SESSIONID);
                        EventBus.getDefault().post(new LogOutEvent());
                        finish();
                    }

                    @Override
                    public void onFail(Exception e) {
                        LogUtils.info(TAG, "e: " + e.toString());
                    }
                });
    }
} 